package com.zhangck.bos2_0.Service.take_delivery.Impl;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.zhangck.bos2_0.Service.take_delivery.PromotionService;
import com.zhangck.bos2_0.dao.PromotionRepository;

import cn.itcast.bos.domain.page.PageBean;
import cn.itcast.bos.domain.system.Permission;
import cn.itcast.bos.domain.take_delivery.Promotion;



/** 
* @author 上午茶
* @version 创建时间：2018年6月7日 下午3:24:55 
* 类说明 
*/
@Service
@Transactional
public class PromotionServiceImpl implements PromotionService {

	@Autowired
	private PromotionRepository promotionRepository;
	
	@Override
	public void Save(Promotion model) {
		promotionRepository.save(model);
	}

	@Override
	public Page<Promotion> findPageData(Pageable request) {
		return promotionRepository.findAll(request);
	}

	@Override
	public Promotion findByID(Integer id) {
		return  promotionRepository.findOne(id);
	}

	@Override
	public PageBean<Promotion> findPage(int page, int rows) {
		System.out.println(page+"aaaaaaaa111111111");
		System.out.println(rows+"aaa1111111111");
		Pageable pageable = new PageRequest(page-1, rows);
		Page<Promotion> page2 = promotionRepository.findAll(pageable);
		
		PageBean<Promotion> pageBean = new PageBean<>();
		pageBean.setTotalCount(page2.getTotalElements());
		pageBean.setPageData(page2.getContent());
		return pageBean;
	}

	@Override
	public Promotion findPromotion(int id) {
		return promotionRepository.findOne(id);
	}

	@Override
	public void tasks() {
		System.out.println("执行了定时更新活动状态任务~~~");
		Date date = new Date();
		 promotionRepository.updateStatus(date);
	}
	


}
